import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    List<List<String>> ret = new ArrayList<>();
    List<String> path = new ArrayList<>();;
    int n;
    public List<List<String>> partition(String s) {
        n = s.length();
        dfs(0, s);
        return ret;
    }

    private void dfs(int pos, String s) {
        if(pos == s.length()) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i = pos; i < n; i++){
            if(isPalindrome(s, pos, i)){
                //如果是回文串 加入路径
                path.add(s.substring(pos, i + 1));
                dfs(i + 1, s);
                path.remove(path.size() - 1);
            }
        }
    }

    private boolean isPalindrome(String s, int left, int right){
        while(left < right) {
            if(s.charAt(left) != s.charAt(right)) return false;
            left++;
            right--;
        }
        return true;
    }
}
